﻿using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using SqlSugar;
using System.Data;
using System.Numerics;
using System.Security.Cryptography;
using System.Security.Policy;
using System.Text.RegularExpressions;
using VM.Common.DataUntil;

using VM.Common.Result;
using VM.Entity.EntityMap.Files;
using VM.Entity.EntityMap.Member;
using VM.Entity.EntityMap.Menu;
using VM.Entity.EntityMap.MsgCode;
using VM.Entity.EntityMap.Token;
using VM.IBLL.Files;
using VM.IDAL;
using static Dm.net.buffer.ByteArrayBuffer;

namespace VM.BLL.Files
{
    public class FilesBLL : BaseBLL, IFilesBLL
    {

        private readonly ISqlSuggarDAL _ISqlSuggarDAL;
        public FilesBLL(ISqlSugarClient client, ISqlSuggarDAL sqlSuggarDAL)
        {
            _ISqlSuggarDAL = sqlSuggarDAL;
        }


        /// <summary>
        /// 添加文件记录
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public ApiDataResult<sys_fileLog> addFileRecordBLL(sys_fileLog obj, int userid) {

            //处理表头
            sys_fileLog fileLog = _ISqlSuggarDAL.Insert(obj);
            
            ApiDataResult<sys_fileLog> res = new ApiDataResult<sys_fileLog>();
            if (fileLog.id != 0)
            {
                res.code = 201;
                res.msg = "添加成功";
                res.data = fileLog;
            }
            else
            {

                res.code = 403;
                res.msg = "添加失败";
                res.data = null;
            }
            return res;





        }

        public ApiDataResult<int> batchAddFileRecordBLL(batchfilesLog obj, int? userid)
        {
            ApiDataResult<int> res = new ApiDataResult<int>();
            try
            {
                for (int i = 0; i < obj.filesLog.Count; i++)
                {
                    obj.filesLog[i].parentId = obj.parentId;
                    //处理表头
                    sys_fileLog fileLog = _ISqlSuggarDAL.Insert(obj.filesLog[i]);
                     
                }
                res.code = 201;
                res.msg = "上传成功";
                res.data = obj.filesLog.Count;

            }
            catch(Exception e) {

                res.code = 403;
                res.msg = "错误："+e.Message;
                res.data = 0;

            }
             
            return res;

        }
    }



}
